package io.renren.modules.simida.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.datasource.annotation.DataSource;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.simida.entity.UserDataEntity;
import io.renren.modules.simida.service.UserDataService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 用户基础表
 *
 * @author miaoguoxin
 * @email ${email}
 * @date 2019-11-16 23:25:54
 */
@RestController
@RequestMapping("simida/userdata")
public class UserDataController {
    @Autowired
    private UserDataService userDataService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("simida:userdata:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userDataService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    @RequiresPermissions("simida:userdata:info")
    @DataSource("slave1")
    public R info(@PathVariable("userId") Long userId){
		UserDataEntity userData = userDataService.getById(userId);

        return R.ok().put("userData", userData);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("simida:userdata:save")
    @DataSource("slave1")
    public R save(@RequestBody UserDataEntity userData){
		userDataService.save(userData);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("simida:userdata:update")
    @DataSource("slave1")
    public R update(@RequestBody UserDataEntity userData){
		userDataService.updateById(userData);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("simida:userdata:delete")
    @DataSource("slave1")
    public R delete(@RequestBody Long[] userIds){
		userDataService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
